import { routerRedux } from 'dva/router';

import { queryLogin } from './service';

import { setAuth } from '@/utils/Auth';

export default {
  namespace: 'users',

  state: {},

  effects: {

   
    *login({ payload }, { call, put }) {
      const response = yield call(queryLogin, payload);
      if (response) {
        setAuth(response.token || '');

        yield put(
          routerRedux.push({
            pathname: '/data/owner',
          })
        );
      }
    },
    *logout(_, { put }) {
      setAuth('');
      window.location.href = '/users/login'
    },

  },

  reducers: {},
};
